﻿using CServiceStack.ServiceHost;
using CServiceStack.WebHost.Endpoints;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace SomeServices
{
    public class SomeBinFormat : IPlugin
    {

        public void Register(IAppHost appHost)
        {
            appHost.ContentTypeFilters.Register("application/somebin", Serialize, DeSerialize);
        }

        public static void Serialize(IRequestContext requestContext, object dto, Stream outputStream)
        {
            BinaryFormatter f = new BinaryFormatter();
            f.Serialize(outputStream, dto);
        }

        public static object DeSerialize(Type type, Stream inputStream)
        {
            BinaryFormatter f = new BinaryFormatter();
            return f.Deserialize(inputStream);
        }
    }
}
